#define __QYQ_MODULE_BUZZER_C_
#include "qyq_module_buzzer.h"

int8_t qyq_module_buzzer_init(struct qyq_module_buzzer_type *this)
{
    if (this == null)
    {
        return -1;
    }

    this->qyq_module_buzzer_config->qyq_module_buzzer_write_status(this->qyq_module_buzzer_config->qyq_module_buzzer_status);
    this->qyq_module_buzzer_config->qyq_module_buzzer_write_frequency(this->qyq_module_buzzer_config->qyq_module_buzzer_frequency);
    this->qyq_module_buzzer_config->qyq_module_buzzer_write_duty(this->qyq_module_buzzer_config->qyq_module_buzzer_duty);

    return 0;
}

int8_t qyq_module_buzzer_on(struct qyq_module_buzzer_type *this) // 打开BUZZER灯
{
    if (this == null)
    {
        return -1;
    }

    this->qyq_module_buzzer_config->qyq_module_buzzer_status = 1;
    this->qyq_module_buzzer_config->qyq_module_buzzer_write_status(this->qyq_module_buzzer_config->qyq_module_buzzer_status);

    return 0;
}

int8_t qyq_module_buzzer_off(struct qyq_module_buzzer_type *this) // 关闭BUZZER灯
{
    if (this == null)
    {
        return -1;
    }

    this->qyq_module_buzzer_config->qyq_module_buzzer_status = 0;
    this->qyq_module_buzzer_config->qyq_module_buzzer_write_status(this->qyq_module_buzzer_config->qyq_module_buzzer_status);

    return 0;
}

int8_t qyq_module_buzzer_get_frequency(struct qyq_module_buzzer_type *this, uint32_t *frequency) // 获取频率
{
    if (this == null)
    {
        return -1;
    }
    if (frequency == null)
    {
        return -1;
    }

    *frequency = this->qyq_module_buzzer_config->qyq_module_buzzer_frequency;

    return 0;
}

int8_t qyq_module_buzzer_set_frequency(struct qyq_module_buzzer_type *this, uint32_t frequency) // 设置频率
{
    if (this == null)
    {
        return -1;
    }

    this->qyq_module_buzzer_config->qyq_module_buzzer_frequency = frequency;
    this->qyq_module_buzzer_config->qyq_module_buzzer_write_frequency(this->qyq_module_buzzer_config->qyq_module_buzzer_frequency);

    return 0;
}

int8_t qyq_module_buzzer_get_duty(struct qyq_module_buzzer_type *this, int8_t *duty) // 获取占空比
{
    if (this == null)
    {
        return -1;
    }
    if (duty == null)
    {
        return -1;
    }

    *duty = this->qyq_module_buzzer_config->qyq_module_buzzer_duty;

    return 0;
}
int8_t qyq_module_buzzer_set_duty(struct qyq_module_buzzer_type *this, int8_t duty) // 设置占空比
{
    if (this == null)
    {
        return -1;
    }

    this->qyq_module_buzzer_config->qyq_module_buzzer_duty = duty;
    this->qyq_module_buzzer_config->qyq_module_buzzer_write_duty(this->qyq_module_buzzer_config->qyq_module_buzzer_duty);

    return 0;
}

int8_t qyq_module_buzzer_get_status(struct qyq_module_buzzer_type *this, uint8_t *status)
{
    if (this == null)
    {
        return -1;
    }
    if (status == null)
    {
        return -1;
    }

    *status = this->qyq_module_buzzer_config->qyq_module_buzzer_status;

    return 0;
}

int8_t qyq_module_buzzer_set_status(struct qyq_module_buzzer_type *this, uint8_t status) // 设置状态
{
    if (this == null)
    {
        return -1;
    }

    this->qyq_module_buzzer_config->qyq_module_buzzer_status = status;
    this->qyq_module_buzzer_config->qyq_module_buzzer_write_status(this->qyq_module_buzzer_config->qyq_module_buzzer_status);

    return 0;
}

int8_t qyq_module_buzzer_create(qyq_module_buzzer_type_t *this, qyq_module_buzzer_config_t *qyq_module_buzzer_config)
{
    if (this == null)
    {
        return -1;
    }
    if (qyq_module_buzzer_config == null)
    {
        return -1;
    }

    this->qyq_module_buzzer_config = qyq_module_buzzer_config;

    this->qyq_module_buzzer_init = qyq_module_buzzer_init;
    this->qyq_module_buzzer_on = qyq_module_buzzer_on;
    this->qyq_module_buzzer_off = qyq_module_buzzer_off;
    this->qyq_module_buzzer_get_status = qyq_module_buzzer_get_status;
    this->qyq_module_buzzer_set_status = qyq_module_buzzer_set_status;
    this->qyq_module_buzzer_get_frequency = qyq_module_buzzer_get_frequency;
    this->qyq_module_buzzer_set_frequency = qyq_module_buzzer_set_frequency;
    this->qyq_module_buzzer_get_duty = qyq_module_buzzer_get_duty;
    this->qyq_module_buzzer_set_duty = qyq_module_buzzer_set_duty;

    return 0;
}
